#include "UnZip.h"

UnZip::UnZip()
{

}

void haffman::unzip(QString path)
{
  int   tem1 = 0, i = 0;
  int   c = 0, len = 0;
  FILE *tem;
  int   num2 = path.length();
  for (int i = num2 - 1; i >= 0; i--)
  {
    if (path[i] == '.') { num2 = i; break; }
  }
  path  = path.left(num2);
  path += formulate;
  qDebug() << formulate;
  strcpy(final_name, path.toLatin1().data());
  tem = fopen(final_name, "wb");
  if (tem == 0)
  {
    return;
  }
  while (tem1 < max_bu || (tem1 == max_bu && i < bu)) // 解压,直到缓冲区结束
  {
    c  = c << 1;
    c |= 1 & (buffer[tem1] >> i);
    ++i;
    if (i >= 8)
    {
      i = 0;
      ++tem1; // bit++
    }
    ++len;
    for (int j = 0; j < bas_len; ++j)
    {
      if ((len == bas[j]->code_len) && (c == bas[j]->code))
      {
        len = c = 0;
        fputc(bas[j]->data, tem);
        break;
      }
    }
  }
  fclose(tem);
}
